<?php
include "header.php";
include "./lib/func.php";
include "./lib/config.php";


if (isLogin() != false){
    header("location:home.php");
    exit;
}

$username = getPost('username');
$pwd = getPost('password');

if (!$username || !$pwd){
    showError('请输入完整的用户名和密码');
}

$redis = connentRedis(Config::REDISHOST, Config::PORT);

$userid = $redis->get('user:username:'. $username. ':userid');
if (!$userid){
    showError('用户名不存在');
}
$password = $redis->get('user:userid:'. $userid. ':password');
if ($pwd !== $password){
    showError('密码错误');
}
//设置cookie

setcookie('username', $username);
setcookie('userid', $userid);

header("location:home.php");


